package main

import (
	"flag"
	"fmt"
	"linuxtest/tool"
	"time"
)

//exec
//https://colobu.com/2020/12/27/go-with-os-exec/

//exec.Command()执行进入docker容器的指令
//https://blog.csdn.net/qq_33690342/article/details/107847551

func main() {
	//hostname, _ := os.Hostname()
	//fmt.Println("主机名", hostname)
	////os.Exit(0)
	//fmt.Println("进程id", os.Getpid())
	//wd, _ := os.Getwd()
	//fmt.Println(wd)
	//os.MkdirAll("test", fs.ModeDir)
	//f, err := exec.LookPath("/main")
	//if err != nil {
	//	fmt.Println(err)
	//}
	//fmt.Println(f)

	//
	//	//tool.MinerdTouch() //创建敏感文件

	//ip
	var SshIp string
	//log4jIp
	var Log4jIp string
	//攻击类型
	var t int

	//./linuxtest -t 0

	flag.StringVar(&SshIp, "SshIp", tool.GlobalObject.SshIp, "暴力破解的主机ip地址")
	flag.StringVar(&Log4jIp, "Log4jIp", tool.GlobalObject.Log4jIp, "lo4j的主机ip地址")
	flag.IntVar(&t, "t", 9, "攻击类型，全部未符合，攻击全部")

	flag.Parse()
	fmt.Printf("SshIp= %v 攻击类型= %v", SshIp, t)

	switch t {
	case 0:
		fmt.Println("暴力破解")
		tool.Brute(SshIp)
	case 1:
		fmt.Println("反弹检测")

	case 2:
		fmt.Println("本地提权")
		tool.SudoRights()
	case 3:
		fmt.Println("Web后门")
		tool.PhpWebShell()
	case 4:
		fmt.Println("可疑行为")
		tool.Suspicious()
	case 5:
		fmt.Println("漏洞利用开始")
		tool.Log4j(Log4jIp)
		tool.Cve4034() //CVE-2021-4034
	case 6:
		fmt.Println("可疑连接开始")
		tool.Minerd("./data/minerd")
	case 7:
		fmt.Println("容器提权开始")
		tool.DockerStartPrivileged()
	case 8:
		fmt.Println("扫描行为")
		tool.Nmap()
	default:
		fmt.Println("暴力破解")
		tool.Brute(SshIp)
		time.Sleep(10 * time.Second)
		fmt.Println("反弹检测")
		time.Sleep(10 * time.Second)
		fmt.Println("本地提权")
		tool.SudoRights()
		fmt.Println("Web后门")
		tool.PhpWebShell()
		time.Sleep(10 * time.Second)
		fmt.Println("可疑行为")
		tool.Suspicious()
		time.Sleep(10 * time.Second)
		fmt.Println("漏洞利用开始")
		tool.Log4j(Log4jIp)
		tool.Cve4034() //CVE-2021-4034
		time.Sleep(10 * time.Second)
		fmt.Println("可疑连接开始")
		tool.Minerd("./data/minerd")
		time.Sleep(10 * time.Second)
		fmt.Println("容器提权开始")
		tool.DockerStartPrivileged()
		time.Sleep(10 * time.Second)
		fmt.Println("扫描行为")
		tool.Nmap()
	}

}
